package com.red.star.wechat.data.mappers;

import com.red.star.wechat.data.core.base.MyMapper;
import com.red.star.wechat.data.entity.EmployeeCard;
import com.red.star.wechat.data.entity.GroupFans;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Set;

/**
 * @author Xucan
 * @Description:蓄客卡与联盟组关联
 * @create 2018-03-02 17:05
 **/
public interface EmployeeCardMapper extends MyMapper<EmployeeCard> {

    int insertEmployeeCard(@Param("fansId") Integer fansId, @Param("employeeId") Integer employeeId, @Param("storeCardId") Integer storeCardId, @Param("groupId") Integer groupId, @Param("status") Integer status);

    List<EmployeeCard> findEmployeeCardByStoreCardId(@Param("id") Integer id);

    int updateEmployeeCardByCardId(@Param("storedCardId") Integer storedCardId, @Param("status") Integer status);

    int updateEmployeeCardByCardIdAndStatus(@Param("storedCardId") Integer storedCardId, @Param("status") Integer status);

    List<EmployeeCard> findNotGroupId(List<Integer> ids, @Param("storedCardId") Integer storedCardId);

    int updateEmployeeCard(List<Integer> idList);

    int updateNotEmployeeCard(@Param("list") List<Integer> ids, @Param("cardId") Integer cardId);

    int updateEmployeeCardByEmployeeIdAndGroupId(@Param("groupId") Integer groupId, @Param("list") List<Integer> list);

    int updateEmployeeCardByGroupId(@Param("groupId") Integer groupId);

    int updateEmployeeCardByStoredCardId(@Param("storedCardId") Integer storedCardId);

    List<GroupFans> findGroupFansByGroupIdSet(@Param("set") Set<Integer> set);

    /**
     * 蓄客卡绑定银行卡
     *
     * @param employeeId   导购ID
     * @param storedCardId 蓄客卡ID
     * @param bankCardId   银行卡ID
     * @return 更新数量
     */
    int updateBankCard(@Param("employeeId") Integer employeeId,
                       @Param("storedCardId") Integer storedCardId,
                       @Param("bankCardId") Integer bankCardId);

    /**
     * 查询导购绑定的某个蓄客卡信息
     *
     * @param employeeId   导购ID
     * @param storedCardId 蓄客卡ID
     * @return 导购蓄客卡
     */
    EmployeeCard findByEmployeeAndStoreCard(@Param("employeeId") Integer employeeId,
                                            @Param("storedCardId") Integer storedCardId);

    EmployeeCard findEntityByEmployeeIdAndCardIdAndGroupId(@Param("employeeId") Integer employeeId, @Param("storedCardId") Integer storedCardId);

    int updateEmployeeCardById(@Param("id") Integer id);

    @Select(value = "select * from t_employee_card t where t.employee_id = #{employeeId} and t.stored_card_id = #{cardId} limit 1")
    EmployeeCard findByCondition(@Param("employeeId") Integer employeeId, @Param("cardId") Integer cardId);

    Integer updateStatusBySettleId(@Param("settleId") Integer settleId);

    EmployeeCard findByEmployeeAndStoreCardAndGruopId(@Param("employeeId") Integer employeeId,@Param("storedCardId") Integer storedCardId);

    Integer updateStatusByCardIds(@Param("list") List<Integer> storedCardIds);

    int updateEmployeeCardByCardIdAndGroupIdAndEmpolyeeId(@Param("storedCardId")Integer storedCardId,@Param("groupId")Integer groupId,@Param("employeeId")Integer employeeId);

    int updateAllEmployeeStatus(@Param("storedCardId")Integer storedCardId,@Param("groupId")Integer groupId,@Param("status") Integer status);

    int updateEmployeeCardNotInCards(@Param("list") List<Integer> list,@Param("groupId") Integer groupId,@Param("status") Integer status);

    int updateEmployeeCardByCardIdAndGroups(@Param("list")List<Integer> list,@Param("cardId") Integer cardId);

   int updateEmployeeCardByCardIdAndGroupList(@Param("list")List<Integer> list,@Param("cardId") Integer cardId);

   int updateEmployeeCardInCards(@Param("list") List<Integer> list,@Param("ids") List<Integer> ids,@Param("groupId") Integer groupId,@Param("status") Integer status);

    List<EmployeeCard> findEmployeeCardByGroupId(@Param("groupId") Integer groupId );

    void updateGroupId(@Param("id") Integer id,@Param("groupId") Integer groupId,@Param("status")Integer status);

    List<Integer> findEmployeeIdsByGrouoId(@Param("groupId") Integer groupId);

    List<Integer> findEmployeeIdsByNotGroupId(@Param("list") List<Integer> list,@Param("groupId") Integer groupId);

    List<Integer> findIdsByGrouoId(@Param("groupId")Integer groupId);

    void updateEmployeeCardByGroupIdEmpty(@Param("list") List<Integer> list);

    void updateEmployeeCardByIdAndGroupId(@Param("id") Integer id,@Param("groupId") Integer groupId,@Param("status")Integer status);

    void updateEmployeeCardOldGroupId(@Param("list") List<Integer> list);
}
